
/*    HTTP Host:  static.ak.fbcdn.net                                          */
/*    Generated:  August 25th 2009 12:48:36 PM PDT                             */
/*      Machine:  10.16.140.109                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/67x0r33w19gk4kcs.pkg.js h:27ano3hf                        */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/67x0r33w19gk4kcs.pkg.js                                   */
function PageCache(max_page_num, max_ttl) {
	if (this === window) {
		return new PageCache(max_page_num, max_ttl);
	}
	this._MAX_PAGE_NUM = typeof max_page_num == "undefined" ? 5 : max_page_num;
	this._MAX_TTL = typeof max_ttl == "undefined" ? 600000 : max_ttl;
	this._storage = {};
}
copy_properties(PageCache.prototype, {_normalizeURI:function (uri) {
	return new URI(uri).getUnqualifiedURI().setFragment("").removeQueryData("ref").toString();
}, addPage:function (uri, properties) {
	uri = this._normalizeURI(uri);
	if (!this._storage[uri]) {
		this._storage[uri] = {};
	}
	var page = this._storage[uri];
	copy_properties(page, properties);
	page.accessTime = page.genTime = (new Date()).getTime();
	this._clearCache();
}, updatePage:function (uri, obj) {
	uri = this._normalizeURI(uri);
	if (!this._storage[uri]) {
		return;
	}
	copy_properties(this._storage[uri], obj);
}, isPageInCache:function (uri) {
	return !!this._storage[this._normalizeURI(uri)];
}, invalidatePage:function (uri) {
	uri = this._normalizeURI(uri);
	delete this._storage[uri];
}, getPage:function (uri) {
	this._clearCache();
	uri = this._normalizeURI(uri);
	var page = this._storage[uri];
	if (!page) {
		return null;
	}
	page.accessTime = (new Date()).getTime();
	return page;
}, _clearCache:function () {
	var cur_time = (new Date()).getTime();
	var oldest = null;
	var page_num = 0;
	for (var uri in this._storage) {
		var page = this._storage[uri];
		var ttl = page.ttl || this._MAX_TTL;
		if (page.genTime < cur_time - ttl) {
			delete this._storage[uri];
			continue;
		}
		if (!oldest || this._storage[oldest].accessTime > page.accessTime) {
			oldest = uri;
		}
		page_num++;
	}
	if (page_num > this._MAX_PAGE_NUM && oldest) {
		delete this._storage[oldest];
	}
}});
var Quickling = {isActive:function () {
	return Quickling._is_active || false;
}, isFeatureEnabled:function (feature) {
	return Quickling._capabilities && Quickling._capabilities[feature];
}, init:function (version, session_length, features, prefetch) {
	if (Quickling._is_initialized) {
		return;
	}
	copy_properties(Quickling, {_is_initialized:true, _is_active:true, _session_length:session_length, _capabilities:features, _is_in_transition:false, _title_interval:false, _ie_cache_title:"", _prefetch:prefetch, _version:version});
	Quickling._instrumentTimeoutFunc("setInterval");
	Quickling._instrumentTimeoutFunc("setTimeout");
	PageTransitions.registerHandler(Quickling._transitionHandler);
	if (Quickling.isFeatureEnabled("page_cache")) {
		Quickling._cache = new PageCache();
		Quickling._invalidate_msgs = [];
		Arbiter.subscribe(Arbiter.NEW_NOTIFICATIONS, Quickling._onNotifications);
		Arbiter.subscribe(Arbiter.REPLAYABLE_AJAX, Quickling._onReplayableAjax);
		Arbiter.subscribe(Arbiter.PAGECACHE_INVALIDATE, Quickling._onCacheInvalidates);
	}
	if (!Quickling.isFeatureEnabled("domain_rewrite")) {
		PageTransitions._rewriteSubDomain = PageTransitions._revertSubDomain = function (uri) {
			return uri;
		};
	}
}, _onNotifications:function (type, notifications) {
	Util.log("Invalidate PageCache due to new notifications");
	Quickling._cache = new PageCache();
	Quickling._invalidate_msgs = [];
}, _onCacheInvalidates:function (type, msgs) {
	if (Quickling.isFeatureEnabled("page_cache") && msgs && msgs.length) {
		for (var ii = 0; ii < msgs.length; ii++) {
			if (parseInt(msgs[ii]) === 0) {
				if (Quickling._is_in_transition && !Quickling.isFeatureEnabled("flush_cache_in_transition")) {
					break;
				}
				if (Quickling._cache.isPageInCache(PageTransitions.getMostRecentURI()) && !Quickling.isFeatureEnabled("flush_cache_in_page_write")) {
					break;
				}
				Util.log("The whole PageCache is invalidated by the server");
				Quickling._cache = new PageCache();
				Quickling._invalidate_msgs = [];
				return;
			}
		}
		Quickling._invalidate_msgs = Quickling._invalidate_msgs.concat(msgs);
	}
}, _refresh_pagelets:function () {
	if (is_empty(window.__listeners)) {
		return;
	}
	for (var ii = 0; ii < Quickling._invalidate_msgs; ii++) {
		var msg = Quickling._invalidate_msgs[ii];
		if (msg in window.__listeners) {
			window.__listeners[msg].forEach(function (pagelet) {
				pagelet.refresh();
			});
		}
	}
}, registerPageCacheHook:function (callback, id) {
	if (!Quickling._is_initialized || !Quickling._is_active || Quickling._is_in_transition || !Quickling.isFeatureEnabled("page_cache")) {
		return;
	}
	var page, cur_uri = PageTransitions.getMostRecentURI();
	if (page = Quickling._cache.getPage(cur_uri)) {
		if (id) {
			for (var ii = 0; ii < page.replays.length; ii++) {
				if (page.replays[ii][0] == id) {
					page.replays.splice(ii, 1);
					ii--;
				}
			}
		}
		page.replays.push([id, callback]);
	}
}, _onReplayableAjax:function (type, request) {
	if (Quickling._is_in_transition) {
		return;
	}
	var regex = Quickling._whitelist_regex;
	if (!regex) {
		regex = Quickling._whitelist_regex = new RegExp(env_get("pagecache_whitelist_regex"));
	}
	if (regex.test(URI(request.getURI()).getPath())) {
		return;
	}
	Quickling.registerPageCacheHook(bind(request, request.replayResponse), request._replayKey);
}, _startQuicklingTransition:function () {
	Quickling._is_in_transition = true;
	window.channelManager && window.channelManager.setActionRequest(true);
}, _stopQuicklingTransition:function () {
	(function () {
		Quickling._is_in_transition = false;
	}).defer();
}, goHashOrGoHere:function (where) {
	var uri = URI.getRequestURI();
	var hash = uri.getFragment();
	if (hash.startsWith("/")) {
		var dest_url = hash;
	} else {
		var dest_url = where;
	}
	setTimeout(function () {
		PageTransitions.go(dest_url, true);
	}, 0);
}, isPageActive:function (uri) {
	if (uri == "#") {
		return false;
	}
	var uri = new URI(uri);
	if (uri.getDomain() && uri.getDomain() != URI().getDomain()) {
		return false;
	}
	var regex = Quickling.isPageActive.regex;
	if (!regex) {
		regex = Quickling.isPageActive.regex = new RegExp(env_get("quickling_inactive_page_regex"));
	}
	if (!Quickling.isFeatureEnabled("full_platform")) {
		query = uri.getQueryData();
		if (query["_fb_qsub"] && query["_fb_qsub"].startsWith("apps")) {
			if (!query["_fb_q"]) {
				return false;
			}
		}
	}
	var testURIString = uri.getPath();
	var queryData = uri.getQueryData();
	if (queryData) {
		testURIString += "?" + URI.implodeQuery(queryData);
	}
	if (regex.test(testURIString)) {
		return false;
	}
	return true;
}, _invoke_callbacks:function (hooks) {
	if (hooks) {
		for (var ii = 0; ii < hooks.length; ii++) {
			try {
				(new Function(hooks[ii]))();
			}
			catch (exception) {
				Util.error("Error %x in executing cached hooks: %s", exception, hooks[ii].toString());
			}
		}
	}
}, _transitionHandler:function (uri) {
	if (Quickling._isTimeToRefresh()) {
		return false;
	}
	if (!Quickling.isPageActive(uri)) {
		return false;
	}
	uri = PageTransitions._revertSubDomain(uri);
	removeHook("onafterloadhooks");
	removeHook("onloadhooks");
	_runHooks("onleavehooks");
	Quickling._startQuicklingTransition();
	var page;
	if (Quickling.isFeatureEnabled("page_cache") && (page = Quickling._cache.getPage(PageTransitions.getMostRecentURI()))) {
		Quickling._invoke_callbacks(page.onpagecache);
		page.incremental_updates = AsyncRequest.stashBundledRequest();
		window.ads_refreshing = false;
	}
	if (Quickling.isFeatureEnabled("page_cache") && (page = Quickling._cache.getPage(uri))) {
		Arbiter.registerCallback(function () {
			$("content").style.visibility = "visible";
			Quickling._invoke_callbacks(page.onafterload);
			Quickling._invoke_callbacks(page.onafterpagecache);
			Quickling._stopQuicklingTransition();
		}, [Arbiter.PAGECACHE_EXEC + "/async", Arbiter.PAGECACHE_EXEC + "/onloads"]);
		AsyncRequest.setBundledRequestProperties({stashedRequests:page.incremental_updates, callback:function () {
			Arbiter.inform(Arbiter.PAGECACHE_EXEC + "/async", true, Arbiter.BEHAVIOR_EVENT);
		}, onInitialResponse:Quickling._onInitialResponse, extra_data:{uri:uri.getQualifiedURI().toString(), version:Quickling._version}, start_immediately:true});
		Quickling._preBootloadHandler();
		Bootloader.loadResources(page.bootload, null, true);
		Quickling._changePageTitle(page.title);
		var body_class = page.body_class || "";
		CSS.setClass(document.body, body_class + (CSS.hasClass(document.body, "chat_body") ? " chat_body" : ""));
		var content_div = $("content");
		content_div.style.visibility = "hidden";
		page.html = page.html.replace(/<span class='muffin_tracking_pixel_start'\/>.*?<span class='muffin_tracking_pixel_end'\/>/g, "");
		DOM.setContent(content_div, HTML(page.html).setDeferred(true));
		if (content_div && content_div.style.height == "1234px") {
			content_div.style.height = "";
		}
		PageTransitions.transitionComplete();
		Quickling._invoke_callbacks(page.onload);
		Quickling._refresh_pagelets();
		page.replays.forEach(function (pair) {
			pair[1]();
		});
		PageTransitions.restoreScrollPosition();
		Arbiter.inform(Arbiter.PAGECACHE_EXEC + "/onloads", true, Arbiter.BEHAVIOR_EVENT);
	} else {
		var quickling_param = {version:Quickling._version};
		uri = new URI(uri).addQueryData({quickling:quickling_param});
		var prefetch = Quickling._prefetch[uri.getPath()];
		if (prefetch && prefetch.length) {
			Bootloader.loadResources(prefetch);
		}
		new AsyncRequest().setPreBootloadHandler(Quickling._preBootloadHandler).setInitialHandler(Quickling._onInitialResponse).setHandler(Quickling._onresponse).setFinallyHandler(PageTransitions.transitionComplete).setMethod("GET").setReadOnly(true).setOption("useIframeTransport", true).setURI(uri).send();
	}
	return true;
}, _preBootloadHandler:function (response) {
	var content_div = ge("content");
	if (content_div) {
		content_div.style.height = "1234px";
		DOM.empty(content_div);
	}
	DOMScroll.scrollTo(new Vector2(0, 0, "document"), false);
	return response && !response.getPayload().redirect;
}, _onInitialResponse:function (response) {
	var payload = response.getPayload();
	if (!payload) {
		return true;
	}
	if (payload.redirect) {
		var redirect_uri = PageTransitions._rewriteSubDomain(payload.redirect);
		if (payload.force || !Quickling.isPageActive(redirect_uri)) {
			go_or_replace(window.location, URI(payload.redirect).removeQueryData("quickling"), true);
		} else {
			PageTransitions.go(redirect_uri, true);
		}
		return false;
	}
	if (payload.version && payload.version != Quickling._version) {
		go_or_replace(window.location, URI(payload.uri).removeQueryData("quickling"), true);
		return false;
	}
	return true;
}, _changePageTitle:function (page_title) {
	page_title = page_title || "Facebook";
	document.title = page_title;
	if (ua.ie()) {
		Quickling._ie_cache_title = page_title;
		if (!Quickling._title_interval) {
			Quickling._title_interval = window.setInterval(function () {
				var fb_title = Quickling._ie_cache_title;
				var ie_title = document.title;
				if (fb_title != ie_title) {
					document.title = fb_title;
				}
			}, 5000, false);
		}
	}
}, cacheResponse:function (response, exec_callbacks) {
	var payload = response.payload;
	Quickling._cache.addPage(PageTransitions.getNextURI(), {title:payload.title, body_class:payload.body_class, html:payload.content["content"], onload:response.onload, onafterload:response.onafterload, bootload:response.bootload, onpagecache:payload.onpagecache, onafterpagecache:payload.onafterpagecache, ttl:payload.page_cache_ttl, replays:[]});
	if (exec_callbacks) {
		Quickling._invoke_callbacks(response.onload);
		onafterloadRegister(function () {
			Quickling._invoke_callbacks(response.onafterload);
		});
	}
}, _onresponse:function (response) {
	var payload = response.payload;
	Quickling._changePageTitle(payload.title);
	var body_class = payload.body_class || "";
	CSS.setClass(document.body, body_class + (CSS.hasClass(document.body, "chat_body") ? " chat_body" : ""));
	if (payload.hasOnbeforeshow) {
		$("content").style.visibility = "hidden";
	}
	for (var div_id in payload.content) {
		var div = ge(div_id);
		var content = payload.content[div_id];
		if (div) {
			if (content === undefined || content === null) {
				Util.warn("Content for div id: " + div_id + " is null");
			} else {
				var html_content = HTML(content).setDeferred(true);
				DOM.setContent(div, html_content);
			}
		} else {
			Util.warn("Unknown content div id: " + div_id);
		}
	}
	if (Quickling.isFeatureEnabled("page_cache") && payload.page_cache_ttl) {
		Quickling.cacheResponse(response);
	}
	var content_div = ge("content");
	if (content_div && content_div.style.height == "1234px") {
		content_div.style.height = "";
	}
	Quickling._stopQuicklingTransition();
}, _isTimeToRefresh:function () {
	Quickling._load_count = (Quickling._load_count || 0) + 1;
	return Quickling._load_count >= Quickling._session_length;
}, _instrumentTimeoutFunc:function (original_name) {
	window[original_name + "_native"] = (function (orig) {
		var _native = function _native(func, delay) {
			return orig(func, delay);
		};
		return _native;
	})(window[original_name]);
	window[original_name] = function _setTimeout(func, delay, clear_on_quickling_event) {
		var timeout_id = window[original_name + "_native"](func, delay);
		if (delay > 0) {
			onunloadRegister(function () {
				clearInterval(timeout_id);
			}, clear_on_quickling_event);
		}
		return timeout_id;
	};
}};
if (window.Bootloader) {
	Bootloader.done(["js/67x0r33w19gk4kcs.pkg.js"]);
}

